window.addEventListener("load", function () {
	const userinp = /^[a-zA-Z0-9\u4e00-\u9fa5\_]{6,20}$/;
	const phoneinp = /^[0-9]{11}$/;
	const chooseinp = /^[a-zA-Z0-9\u4e00-\u9fa5\_]{6,12}$/;
	$("#bt").onclick = function () {
		// 用户名
		if (!userinp.test($("#user").value)) {
			// input边框变红，提示文字显示，并且为红色
			$("#user").style.border = "1px solid red";
			$("#user").nextElementSibling.textContent = "用户名（6-20位字母数字）";
			$("#user").nextElementSibling.style.color = "red";
		} else {
			$("#user").style.border = "1px solid black";
			$("#user").nextElementSibling.textContent = "";
		}
		//  手机号
		if (!phoneinp.test($("#phone").value)) {
			$("#phone").style.border = "1px solid red";
			$("#phone").nextElementSibling.textContent = "请输入手机号码";
			$("#phone").nextElementSibling.style.color = "red";
		} else {
			$("#phone").style.border = "1px solid black";
			$("#phone").nextElementSibling.textContent = "";
		}
		// 密码
		if (!chooseinp.test($("#choose").value)) {
			$("#choose").style.border = "1px solid red";
			$("#choose").nextElementSibling.textContent = "请输入6-12位密码";
			$("#choose").nextElementSibling.style.color = "red";
		} else {
			$("#choose").style.border = "1px solid black";
			$("#choose").nextElementSibling.textContent = "";
		}
		// 验证码
		if ($("#veri").value.length < 1) {
			$("#veri").style.border = "1px solid red";
			// $("#veriinp").nextElementSibling.textContent = "请输入验证码";
			// $("#veriinp").placeholder.style.color = "red";
		} else {
			$("#veri").style.border = "1px solid black";
			// $("#veriinp").placeholder.style.color = "black";
		}

		return false; // 阻止提交事件
	};
	// 发送验证码
	// 给按钮绑定点击事件
	$("#bbt").onclick = function () {
		// 声明倒计时秒数10
		let a = 60;
		let timer = window.setInterval(function () {
			a--;
			$("#bbt").textContent = `发送验证码(${a})`;
			$("#bbt").disabled = true;
			if (a <= 0) {
				$("#bbt").textContent = "发送验证码";
				window.clearInterval(timer);
				$("#bbt").disabled = false;
			}
		}, 1000);
	};
});
